package com.szyportal.web.back.controller.szyportal;

import com.szyportal.common.annotation.Log;
import com.szyportal.common.core.controller.BaseController;
import com.szyportal.common.core.domain.AjaxResult;
import com.szyportal.common.core.page.TableDataInfo;
import com.szyportal.common.enums.BusinessType;
import com.szyportal.common.utils.poi.ExcelUtil;
import com.szyportal.custom.domain.WPartner;
import com.szyportal.custom.service.IWPartnerService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【主要合作方】Controller
 * 
 * @author ruoyi
 * @date 2025-03-27
 */
@Controller
@RequestMapping("/back/custom/partner")
public class WPartnerController extends BaseController
{
    private String prefix = "back/szyportal/partner";

    @Autowired
    private IWPartnerService wPartnerService;

    @RequiresPermissions("custom:partner:view")
    @GetMapping()
    public String partner()
    {
        return prefix + "/partner";
    }

    /**
     * 查询【主要合作方】列表
     */
    @RequiresPermissions("custom:partner:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WPartner wPartner)
    {
        startPage();
        List<WPartner> list = wPartnerService.selectWPartnerList(wPartner);
        return getDataTable(list);
    }

    /**
     * 导出【主要合作方】列表
     */
    @RequiresPermissions("custom:partner:export")
    @Log(title = "【主要合作方】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WPartner wPartner)
    {
        List<WPartner> list = wPartnerService.selectWPartnerList(wPartner);
        ExcelUtil<WPartner> util = new ExcelUtil<WPartner>(WPartner.class);
        return util.exportExcel(list, "【主要合作方】数据");
    }

    /**
     * 新增【主要合作方】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【主要合作方】
     */
    @RequiresPermissions("custom:partner:add")
    @Log(title = "【主要合作方】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WPartner wPartner)
    {
        return toAjax(wPartnerService.insertWPartner(wPartner));
    }

    /**
     * 修改【主要合作方】
     */
    @RequiresPermissions("custom:partner:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WPartner wPartner = wPartnerService.selectWPartnerById(id);
        mmap.put("wPartner", wPartner);
        return prefix + "/edit";
    }

    /**
     * 修改保存【主要合作方】
     */
    @RequiresPermissions("custom:partner:edit")
    @Log(title = "【主要合作方】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WPartner wPartner)
    {
        return toAjax(wPartnerService.updateWPartner(wPartner));
    }

    /**
     * 删除【主要合作方】
     */
    @RequiresPermissions("custom:partner:remove")
    @Log(title = "【主要合作方】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wPartnerService.deleteWPartnerByIds(ids));
    }
}
